package com.mes.web.controller.biz;

import java.util.List;
import java.util.HashMap;
import java.util.Map;
import com.mes.common.annotation.Log;
import com.mes.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.mes.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mes.common.enums.BusinessType;
import com.mes.common.utils.SecurityUtils;
import com.mes.common.utils.poi.ExcelUtil;
import com.mes.framework.cache.DictUtils;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.mes.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.mes.biz.domain.BizConfig;
import com.mes.biz.service.BizConfigService;

/**
 * 系统控制项Controller
 * @author hwg
 * @email hwg
 * @date 2023-03-27
 */
@RestController
@RequestMapping("/biz/bizConfig")
public class BizConfigController extends BaseController {

    @Autowired
    private BizConfigService bizConfigService;

    /**
     * 查询系统控制项列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizConfig:list')")
    @GetMapping("/list")
    public R<PageInfo> list(BizConfig bizConfig, HttpServletRequest request, HttpServletResponse response) {
        bizConfig.setPage(new PageDomain(request, response));
        return R.data(bizConfigService.findPage(bizConfig));
    }

    /**
     * 获取系统控制项详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizConfig:query')")
    @GetMapping(value = "/{id}")
    public R<BizConfig> detail(@PathVariable("id") String id) {
        return R.data(bizConfigService.get(id));
    }

    /**
     * 新增系统控制项
     */
    @PreAuthorize("@ss.hasPermi('biz:bizConfig:add')")
    @Log(title = "系统控制项", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  BizConfig bizConfig) {
        bizConfig.setTenantId(SecurityUtils.getTenantId());
        return R.status(bizConfigService.save(bizConfig));
    }

    /**
     * 修改系统控制项
     */
    @PreAuthorize("@ss.hasPermi('biz:bizConfig:edit')")
    @Log(title = "系统控制项", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated BizConfig bizConfig) {
        return R.status(bizConfigService.save(bizConfig));
    }

    /**
     * 删除系统控制项
     */
    @PreAuthorize("@ss.hasPermi('biz:bizConfig:remove')")
    @Log(title = "系统控制项", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.status(bizConfigService.deleteBizConfigByIds(ids));
    }


    /**
     * 导出系统控制项列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizConfig:export')")
    @Log(title = "系统控制项", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(BizConfig bizConfig) {
        List<BizConfig> list = bizConfigService.findList(bizConfig);
        ExcelUtil<BizConfig> util = new ExcelUtil<BizConfig>(BizConfig.class);
        return util.exportExcel(list, "系统控制项数据");
    }

    /**
     * 根据字典类型查询字典数据信息等其他自定义信息
     */
    @GetMapping(value = "/getInitData/{dictTypes}")
    public R getInitData(@PathVariable String dictTypes) {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.putAll(DictUtils.getMultiDictList(dictTypes));
        return R.data(dataMap);
    }

}
